package com.zp.self.module.令牌桶.controller;

import com.zp.self.authentication.SysLoginService;
import com.zp.self.entity.LoginBody;
import com.zp.self.util.Constants;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 登录验证
 *
 * @author zengpeng
 */
@RestController
public class SysLoginController {

    @Resource
    SysLoginService loginService;


    /**
     * 登录方法
     *
     * @param loginBody 登录信息
     * @return 结果
     */
    @PostMapping("/login")
    public Map login(@RequestBody LoginBody loginBody) {
        // 生成令牌
        String token = loginService.login(loginBody.getUsername(), loginBody.getPassword());
        Map<String, Object> data = new HashMap<>();
        data.put(Constants.LOGIN.TOKEN, token);
        return data;
    }

}
